cmake_minimum_required(VERSION 3.14)

project(bios)
find_package(PkgConfig REQUIRED)
pkg_search_module(GLIB REQUIRED glib-2.0)
pkg_search_module(GMODULE REQUIRED gmodule-2.0)

set(TARGET_LIB ${PROJECT_NAME})
set(BUILD_DIR temp)

if (EXISTS "${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
    include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
    conan_basic_setup()
else()
    find_package(libmc4lua REQUIRED)
endif()

set(APP_INSTALL_DIR opt/bmc/apps/${PROJECT_NAME})
set(LUACLIB_INSTALL_DIR ${APP_INSTALL_DIR}/luaclib)
add_subdirectory("src/lualib-src")

if(BUILD_MANUFACTURE)
    install(DIRECTORY manufacture/ DESTINATION ${APP_INSTALL_DIR} OPTIONAL)
endif()
install(DIRECTORY src/lualib DESTINATION ${APP_INSTALL_DIR} OPTIONAL)
install(DIRECTORY include/ DESTINATION opt/bmc/lualib OPTIONAL)
install(DIRECTORY src/service DESTINATION ${APP_INSTALL_DIR} OPTIONAL)
install(DIRECTORY gen/${PROJECT_NAME}/ DESTINATION ${APP_INSTALL_DIR} OPTIONAL)
install(DIRECTORY gen/class DESTINATION ${APP_INSTALL_DIR} OPTIONAL)
install(FILES mds/schema.json DESTINATION ${APP_INSTALL_DIR}/mds OPTIONAL)
install(FILES mds/service.json DESTINATION ${APP_INSTALL_DIR}/mds OPTIONAL)
install(DIRECTORY dist/user_conf/rootfs/ DESTINATION . USE_SOURCE_PERMISSIONS OPTIONAL)
install(FILES dist/config.cfg DESTINATION ${APP_INSTALL_DIR} OPTIONAL)

if(CONAN_DEFS_CHIPV2_ENABLE)
    install(FILES src/lualib/macros/chipv2/spi_def.lua DESTINATION ${APP_INSTALL_DIR}/lualib/macros)
else()
    install(FILES src/lualib/macros/chipv1/spi_def.lua DESTINATION ${APP_INSTALL_DIR}/lualib/macros)
endif()